Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arduino service #812

Closed
wants to merge 621 commits into from
Closed

Arduino service #812

wants to merge 621 commits into from

Conversation

billonalex
Copy link

@billonalex billonalex commented May 20, 2020

Pull Request check-list

To ensure your Pull Request can be accepted as fast as possible, make sure to review and check all of these items:

  • If your changes affects code, did your write the tests?
  • Are tests passing? (npm test on both front/server)
  • Is the linter passing? (npm run eslint on both front/server)
  • Did you run prettier? (npm run prettier on both front/server)
  • If you are adding a new features/services, did you run integration comparator? (npm run compare-translations on front)
  • Did you add fake requests data for the demo mode (front/src/config/demo.json) so that the demo website is working without a backend? (if needed) See https://demo.gladysassistant.com.
  • If your changes modify the API (REST or Node.js), did you modify the API documentation? (Documentation is based on comments in code)
  • If you are adding a new features/services which needs explanation, did you modify the user documentation? See the GitHub repo and the website.

NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open.

Description of change

Please provide a description of the change here. It's always best with screenshots, so don't hesitate to add some!

This PR is about the Arduino service. Gladys will now be able to interact with Arduino card. The user uploads the generic code on the card, setups the service, creates the device, and interacts with hardware.

@billonalex billonalex marked this pull request as ready for review May 25, 2020 17:53
@billonalex billonalex changed the title Arduino service [WIP] Arduino service May 27, 2020
@codecov
Copy link

codecov bot commented May 27, 2020

Codecov Report

Merging #812 (f7a4b01) into master (3febb17) will decrease coverage by 0.04%.
The diff coverage is 92.92%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #812      +/-   ##
==========================================
- Coverage   94.52%   94.47%   -0.05%     
==========================================
  Files         485      497      +12     
  Lines        6444     6642     +198     
==========================================
+ Hits         6091     6275     +184     
- Misses        353      367      +14     
Impacted Files Coverage Δ
server/lib/device/light/light.getLightsInRoom.js 100.00% <ø> (ø)
server/services/usb/api/usb.controller.js 100.00% <ø> (ø)
server/services/arduino/lib/listen.js 80.00% <80.00%> (ø)
server/services/arduino/lib/init.js 84.00% <84.00%> (ø)
server/services/arduino/lib/setup.js 84.61% <84.61%> (ø)
server/services/arduino/lib/send.js 90.90% <90.90%> (ø)
server/services/arduino/lib/device.setValue.js 94.44% <94.44%> (ø)
server/services/arduino/lib/onPortData.js 94.73% <94.73%> (ø)
server/services/arduino/api/arduino.controller.js 100.00% <100.00%> (ø)
server/services/arduino/index.js 100.00% <100.00%> (ø)
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3febb17...f7a4b01. Read the comment docs.

@billonalex billonalex changed the title [WIP] Arduino service Arduino service May 27, 2020
@VonOx
Copy link
Contributor

VonOx commented May 27, 2020

Hi @billonalex , how did you sync your fork from master ?

@billonalex
Copy link
Author

Hi @VonOx ,

To merge from the original repo, I used :

git remote add upstream https://github.com/GladysAssistant/Gladys.git

and

git fetch --all
git merge upstream/master
git push

each time a new commit appeared in GladysAssistant repo.

@VonOx
Copy link
Contributor

VonOx commented May 27, 2020

Ok its fine ! Something weird with my github ( and me :-) )
I saw philips-hue stuff in PR related to arduino , so I was confused.

Nice job btw

@billonalex
Copy link
Author

Yeah, when I ran prettier, the "tests/services/philips-hue/lights.json" changed, which caused bugs during tests ! So I manually corrected the file by cancelling changes prettier made on this file and discarding when running prettier after. Technically the file is now the same as it used to be 🙂

@Pierre-Gilles
Copy link
Contributor

Thanks for your PR !

I agree with @VonOx, @billonalex I'm not sure you're merging your fork with master the right way, I see some files from other PRs affected here, and sometimes it's conflicting with the master branch:

Screenshot 2020-06-02 at 10 32 48

@billonalex
Copy link
Author

Hi @Pierre-Gilles,

I just merged your latest commits. There shouldn't be conflict anymore.

However, I don't understand how could I merge my fork with master the right way ? I do the exact step as described upper each time I have to merge changes.

@Pierre-Gilles
Copy link
Contributor

This time it seems good! You maybe did a mistake previously :)

About codecov not passing, the diff coverage is available here:

https://codecov.io/gh/GladysAssistant/Gladys/compare/354d2f6e974f4bc3b95d9139059b026ca5d66275...e239755d0c979fef0a7257aeab0c6611e353b5c8/diff

@billonalex
Copy link
Author

Perfect :)

However, I'm a little confused about codecov... If some changes have to be made could you please give me some directions ?

Thank you

@Pierre-Gilles
Copy link
Contributor

Codecov indicates the lines not covered by tests ! To fix codecov, you need to write tests so that every lines indicated by codecov are covered

Example:

Screenshot 2020-06-02 at 16 43 28

Here, it seems that the configure function is not fully covered in tests

Does it make sense? :)

Copy link
Contributor

@Pierre-Gilles Pierre-Gilles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this very great PR ! 👏

This is rare to have such quality in a first shot, so congrats, you did something really great :)

I just read the server code for now, and I have a few feedbacks, mostly on error handling.

While it's great the catch errors, something errors should be thrown and sent back to the frontend so the frontend knows that something is wrong.

In Gladys 4, the user will never see the logs of Gladys 4, so the errors should be visible in the UI !

* @apiGroup Arduino
*/
async function setup(req, res) {
arduinoManager.setup(req.body);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I saw, this function never rejects any errors

How is the user going to know when something went wrong?

Error handling is very important and you shouldn't res.json({ success: true}); all the time. If something is wrong, reject a nice error message and in the UI display an explicit error message

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified setup.js script to return a json { success: true} or { success: false} to the front.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not what I said! You should reject errors, not resolves with { success: false}. When something is wrong, the HTTP code should not be "200 ok" but should be relative to the error.

This is an example in the Philips Hue library : https://github.com/GladysAssistant/Gladys/blob/master/server/services/philips-hue/lib/light/light.setValue.js

When something is wrong, we throw a clear error which will results in a "404" error, clear for the client.

We provide lots of errors in utils/coreErrors and utils/httpErrors. Let me know if you need more help :)

server/services/arduino/lib/device.configure.js Outdated Show resolved Hide resolved
server/services/arduino/lib/device.setValue.js Outdated Show resolved Hide resolved
@billonalex
Copy link
Author

@Pierre-Gilles Thanks for your review 🙂

Changes are made. I run a prettier, local coverage and I push my changes !

@billonalex
Copy link
Author

Hello @Pierre-Gilles

Did you have the time to look at changes that I made ? 🙂

Copy link
Contributor

@Pierre-Gilles Pierre-Gilles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your changes! I added a feedback on the error handling :)

Btw, I'm waiting for people to test it on the forum before merging this.

@Pierre-Gilles
Copy link
Contributor

Hi! Just wanted to know what's the status of this PR? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants